package com.itheima.mapper;

import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {


    List<Student> list(StudentQueryParam studentQueryParam);

    void deleteById(List<Integer> ids);
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id) values " +
            "(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId})")
    void add(Student student);
    @Select("select s.*,c.name clazzName from student s  left join clazz c on c.id = s.clazz_id where s.id = #{id}")
    Student getById(Integer id);
    @Update("update student set name = #{name},no=#{no},phone=#{phone},gender=#{gender},degree=#{degree},id_card=#{idCard},is_college=#{isCollege},address=#{address},graduation_date=#{graduationDate},violation_count=#{violationCount},violation_score=#{violationScore},clazz_id=#{clazzId} where id=#{id}")
    void update(Student student);

    void updateViolation(Integer id, Integer score);





    List<Map> getStudentCountData();

    List<Map> countStudentDegreeData();
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer countByClazzId(Integer id);
}
